<?php 
declare (strict_types = 1);
namespace app\api\controller;
use app\common\controller\Api;
use think\Request;
class BusinessGg extends Api
{

    //用户端-首页-最新公告
    public function user_index()
    {
        $post = param();
        //门店ID
        if(!isset($post['id'])) return msgerror('参数缺失');
        $limit = input('limit') ?: 20;
        $data = $this->model->where([['business_id','=',$post['id']]])->order('id desc')->paginate($limit);
        return datasuccess($data);
    }
//    //用户端-公告信息
//    public function gr_index()
//    {
//        $post = param();
//        //门店ID
//        if(!isset($post['id'])) return msgerror('参数缺失');
//    }
    public function index()
    {
        $this->businessCheckLogin();
        $post = param();
        $limit = input('limit') ?: 20;
        $data = $this->model->where([['business_id','=',$this->businessinfo['id']]])->order('id desc')->paginate($limit);
        return datasuccess($data);
    }
    public function add()
    {
        $this->businessCheckLogin();
        $post = param();
        $post['business_id'] = $this->businessinfo['id'];
        $this->model->save($post);
        return datasuccess([],'添加成功');
    }
    //数据修改
    public function upload()
    {
        $this->businessCheckLogin();
        $post = array_filter(input('post.'));
        if(!empty($post)){
            if(!isset($post['id'])) return msgerror('缺少id');
            $a = $this->model::update($post);
            return datasuccess();
        }else{
            return msgerror('缺少参数');
        }
    }
    //删除数据
    public function delete()
    {
        $this->businessCheckLogin();
        if (!input('post.id')) {
            return msgerror('缺少参数id');
        }
        if (strstr((string)input('post.id'), ',')) {
            $id = explode(',', input('post.id'));
        } else {
            $id = input('post.id');
        }
        $this->model::destroy($id);
        return datasuccess([], '删除成功');
    }
}